package com.ly.cloud.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.plugins.Page;
import com.ly.cloud.common.mybatisplus.plugins.PageInfo;
import com.ly.cloud.dto.ApplyCourseDto;
import com.ly.cloud.dto.ApplyCourseXsDto;
import com.ly.cloud.service.ApplyCourseService;
import com.ly.cloud.vo.ApplyCourseTableVo;
import com.ly.cloud.vo.ApplyCourseVo;
import com.ly.cloud.vo.CourseBaseVo;
import com.ly.cloud.web.utils.WebResponse;

/**
 * 课程申请
 * @author siqi
 * @date 2018-12-18
 * 
 * 对接口进行开发
 * @caihuihai
 * @date 2018-12-21
 */
@RestController
@RequestMapping("/applyCourse")
public class ApplyCourseController {

	@Autowired
	public ApplyCourseService applyCourseService;

	/**
	 * 分页查询课程申请列表
	 * 
	 * @param pageNum
	 * @param pageSize
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/queryPage", method = RequestMethod.GET)
	public WebResponse<PageInfo<ApplyCourseTableVo>> queryPage(@RequestParam int pageNum, @RequestParam int pageSize,
			ApplyCourseDto dto) {
		Page<ApplyCourseTableVo> queryPage = applyCourseService
				.queryPage(new Page<ApplyCourseTableVo>(pageNum, pageSize), dto);
		return new WebResponse<PageInfo<ApplyCourseTableVo>>().success(PageInfo.toPageInfo(queryPage));
	}
	
	/**
	 * 保存/提交审核课程申请
	 * @param loginUserName
	 * @param applyCourseDto
	 * @return
	 */
	@RequestMapping(value = "/insertApplyCourse",method = RequestMethod.POST)
	public WebResponse<Boolean> insertApplyCourse(
			@RequestHeader(required = false, value = "loginUserId") String loginUserId,
			@RequestHeader(required = false, value = "loginUserName") String loginUserName,
			@RequestBody ApplyCourseDto applyCourseDto) {
		Boolean isInsert = applyCourseService.insertCourse(loginUserId,loginUserName, applyCourseDto);
		return new WebResponse<Boolean>().success(isInsert);
	}
	
	
	/**
	 * 根据课程编号查询课程申请信息（包括学时）
	 * @param kch 课程编号
	 * @return
	 */
    @RequestMapping(value = "/findKcxxByKch", method = RequestMethod.GET)
    public WebResponse<ApplyCourseVo> findTeachList(@RequestParam String kch){
    	ApplyCourseVo vo = applyCourseService.findKcxxByKch(kch);
        return new WebResponse<ApplyCourseVo>().success(vo) ;
    }
    
    
    /**
	 * 批量删除课程
	 * @param dto
	 * @return
	 */
	@RequestMapping(value = "/batchDelKc", method = RequestMethod.POST)
	public WebResponse<Boolean> batchDelKc(@RequestBody List<ApplyCourseDto> kcList) {
		boolean rs = applyCourseService.batchDelKc(kcList);
		return new WebResponse<Boolean>().success(rs);
	}
	
}
